<template>
  <div class="tab_control">
    <div
      :class="['tab_control_item', { active: curIdx === index }]"
      v-for="(item, index) of titles"
      :key="index"
      @click="toggle(index)"
    >
      <span>{{ item }}</span>
    </div>
  </div>
</template>

<script>
export default {
  name: 'TabBarControl',
  props: {
    titles: {
      type: Array,
      default () {
        return []
      }
    }
  },
  data () {
    return {
      curIdx: 0
    }
  },
  methods: {
    toggle (index) {
      this.curIdx = index

      this.$emit('toggleTab', index)
    }
  }
}
</script>

<style lang="scss" scoped>
.tab_control {
  display: flex;
  text-align: center;
  line-height: 40px;

  &_item {
    flex: 1;

    span {
      padding: 5px;
    }

    &.active {
      color: $--color-high-text;

      span {
        border-bottom: 2px solid $--color-high-text;
      }
    }
  }
}
</style>
